/**
 * @author 岳晓磊
 */
 /**
  * 生成表格
  */
var sort = null,bbar="",grid = new Ext.grid.GridPanel();  
var status = null;
function inituserlist(){
	Ext.menu.RangeMenu.prototype.icons = {
	  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
	  lt: './ajaxFramework/ext-2.1/img/less_then.png',
	  eq: './ajaxFramework/ext-2.1/img/equals.png'
	};
	Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';
	var colModel = new Ext.grid.ColumnModel([
		{header:'印章名称',dataIndex:'sealName'},
		{header:'申请日期',dataIndex:'dateTime1',menuDisabled : true},
		{header:'状态',dataIndex:'status',menuDisabled : true},
		{header:'id',dataIndex:'id',hidden:true},
		{header:'taskid',dataIndex:'taskid',hidden:true},
		{header:'flowid',dataIndex:'flowid',hidden:true},
		{header:'操作',dataIndex:'operate',menuDisabled : true,renderer:function(s,m,rec){
		   status = rec.data.status;
		   if(status=='退回'){
		      return "<a href="+"javascript:trackTo('"+rec.data.flowid+"','gen')>跟踪</a> <a href="+"javascript:sealTo('"+rec.data.id+"','genReturn','"+rec.data.taskid+"')>进入</a>";
		   }else{
		      return "<a href="+"javascript:trackTo('"+rec.data.flowid+"','gen')>跟踪</a> <a href="+"javascript:sealTo('"+rec.data.id+"','genSelect')>进入</a>";
		   }
           
		}}
	]);
	var filters = new Ext.grid.GridFilters({
		 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
		   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
		   for(var key in p) {
		      if( key != 'start' && key != 'limit' )
		   //if(regex.test(key)) {
		    delete p[key];
		            //}
		               }
          },
	     buildQuery: function(filters) {	
		  // filters 就是getFilterData返回的值, 代码中push入去的对象
		  var p = {};
		  for(var i=0, len=filters.length; i<len; i++) {
		      var f = filters[i];
		      
		      // 取得在GridFilters中定义的filters中的一个filter
		      var filter = this.getFilter( f.field );
		      // 取得传递到server的参数名称
		      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
		      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
		      
		      if( value != '' ) p[ name ] = value;
		  }
		  return p;
		   },	
		  filters:[
		 	{type: 'string',  dataIndex: 'sealName'}
	]}); 
	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url:url,
		fields:['sealName','dateTime1','status','id','taskid','flowid','operate'],
		root:'root',
		totalProperty:'totalProperty'
	});
	var bbar = new Ext.PagingToolbar({
		pageSize:10,
		store:sort,
		plugins: filters,
		displayInfo:true,
		emptyMsg:'没有记录'
	});
	
   grid = new Ext.grid.GridPanel({
		title:'一般公章用印',
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		autoHeight:true,
		tbar:[{
			 text: '申请',
             iconCls: 'silk-add',
             handler:function(){
             	window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/useseal/sealTo.do?method=genForm';
             }
		}],
		bbar:bbar,
		plugins: filters,
		viewConfig:{
			forceFit:true
		}
	});
	
	if(Ext.get('startid')){
		start = Ext.get('startid').getValue();
		sort.load({params:{start:0, limit: 10},callback:function(){
			grid.hide();
			bbar.hide();
			bbar.changePage(Ext.get('page').getValue());
			grid.show();
			bbar.show();
		}});
		return;
	}
	else
	{
		sort.load({params:{start:0, limit: 10}});
	}
    
}
/**
	 * 禁用一个用户
	 * @param {} id 用户ID
	 */
	function sealTo(id,method,taskid){
	   window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/useseal/sealTo.do?method='+method+'&id='+id+'&taskid='+taskid;
	}
	function trackTo(flowid,useSealType){
	   window.location.href=Ext.get('basePath').getValue()+'useSeal/trackList.jsp?flowid='+flowid+'&useSealType='+useSealType;
	}
	